package com.hp.modules.sys.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.hp.common.annotation.DictEnum;
import com.hp.common.base.CodedEnum;
import com.hp.common.base.YesNoEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import tk.mybatis.mapper.annotation.LogicDelete;

import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;

/**
 * @author:mcfan
 * @description:请求日志-实体类
 * @date: create in 9:21 2021/4/8
 */
@Table(name = "sys_request_log")
@ApiModel(description = "请求日志")
public class SysRequestLog implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = -1L;
    @Id
    @ApiModelProperty(value="主键")
    private Long id;
    @ApiModelProperty(value = "请求唯一标识")
    private String trackId;
    @ApiModelProperty(value = "请求类型(10->添加|SAVE,20->修改|UPDATE,30->删除|REMOVE,40->导入|IMPORT,50->导出|EXPORT,99->其他|OTHER)")
    private RequestTypeEnum requestType;
    @ApiModelProperty(value = "请求路径")
    private String uri;
    @ApiModelProperty(value = "请求url参数")
    private String queryString;
    @ApiModelProperty(value = "请求方式")
    private String method;
    @ApiModelProperty(value = "操作说明")
    private String description;
    @ApiModelProperty(value = "客户端ip")
    private String ip;
    @ApiModelProperty(value = "请求体")
    private String body;
    @ApiModelProperty(value = "请求token")
    private String token;
    @ApiModelProperty(value = "用户id")
    private Long userId;
    @ApiModelProperty(value = "用户名")
    private String userName;
    @ApiModelProperty(value = "返回参数")
    private String returnData;
    @ApiModelProperty(value = "开始时间")
    private Date startTime;
    @ApiModelProperty(value = "结束时间")
    private Date endTime;
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;
    @ApiModelProperty(value = "是否删除(1->未删除|NO,2->已删除|YES)")
    @LogicDelete(isDeletedValue= YesNoEnum.Y,notDeletedValue=YesNoEnum.N)
    private YesNoEnum isDeleted;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTrackId() {
        return trackId;
    }

    public void setTrackId(String trackId) {
        this.trackId = trackId;
    }

    public RequestTypeEnum getRequestType() {
        return requestType;
    }

    public void setRequestType(RequestTypeEnum requestType) {
        this.requestType = requestType;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getQueryString() {
        return queryString;
    }

    public void setQueryString(String queryString) {
        this.queryString = queryString;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getReturnData() {
        return returnData;
    }

    public void setReturnData(String returnData) {
        this.returnData = returnData;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public YesNoEnum getIsDeleted() {
        return isDeleted;
    }

    public void setIsDeleted(YesNoEnum isDeleted) {
        this.isDeleted = isDeleted;
    }

    @DictEnum(key = "sys_request_log_request_type",name = "请求类型")
    public enum RequestTypeEnum implements CodedEnum {
        /**
         * 添加
         */
        SAVE(10,"添加"),
        /**
         * 修改
         */
        UPDATE(20,"修改"),
        /**
         * 删除
         */
        REMOVE(30,"删除"),
        /**
         * 导入
         */
        IMPORT(40,"导入"),
        /**
         * 导出
         */
        EXPORT(50,"导出"),
        /**
         * 其他
         */
        OTHER(99,"其他");

        ;
        private int value;
        private String name;

        @JsonCreator
        public static RequestTypeEnum forValue(int value){
            return CodedEnum.codeOf(RequestTypeEnum.class,value).get();
        }

        RequestTypeEnum(int value, String name) {
            this.value = value;
            this.name = name;
        }

        @Override
        @JsonValue
        public int getValue() {
            return value;
        }

        @Override
        public String getName() {
            return name;
        }
    }
}
